'''
https://leetcode.cn/problems/find-the-longest-substring-containing-vowels-in-even-counts/description/
'''


def update_state(state, c):
    if c == 'a':
        return state ^ 0b00001
    elif c == 'e':
        return state ^ 0b00010
    elif c == 'i':
        return state ^ 0b00100
    elif c == 'o':
        return state ^ 0b01000
    elif c == 'u':
        return state ^ 0b10000
    else:
        return state

class Solution:
    def findTheLongestSubstring(self, s: str) -> int:
        state = 0b00000
        dic = {0: -1}
        ans = 0
        for i, c in enumerate(s):
            state = update_state(state, c)
            if state == 0:
                ans = i + 1
            else:
                if state in dic:
                    ans = max(ans, i - dic[state])
            if state not in dic:
                dic[state] = i
        return ans
